<template>
	<view class="addSpecificationPage">
		<!--  -->

		<view class="addSpecificationContent">
			<view class="font-weight_bold">
				是否开启
			</view>
			<view class="myNmae flex-between margin-top_30rpx">
				<view style="margin-left:-20rpx;" class="">
					<radio-group style="transform:scale(0.8) " @change="radioChange" class="flex-start-center ">
						<label class="flex-start-center  margin-right_16rpx" v-for="(item, index) in items"
							:key="item.value">
							<view>
								<radio :value="item.value" :checked="index === current" />
							</view>
							<view>{{item.name}}</view>
						</label>
					</radio-group>
				</view>

			</view>
			<view class="font-weight_bold margin-top_40rpx">
				提现方式
			</view>
			<view class="myNmae flex-between margin-top_30rpx">
				<view style="margin-left:-20rpx;" class="">
					<radio-group style="transform:scale(0.8) " @change="radioChange1" class="flex-start-center ">
						<label class="flex-start-center  margin-right_16rpx" v-for="(item, index) in pay"
							:key="item.value">
							<view>
								<radio :value="item.value" :checked="index === current1" />
							</view>
							<view>{{item.name}}</view>
						</label>
					</radio-group>
				</view>

			</view>
			<!-- <view class="font-weight_bold margin-top_40rpx">
				兑换比例
			</view>
			<view class="edit flex-start-center padding-left_30rpx margin-top_16rpx">
				<input class="uni-input" maxlength="3" type="number" v-model="form.withdrawal_ratio"
					placeholder="请输入小标题名称" />


			</view> -->
			<view class="margin-top_10rpx">
				<text style="color: rgb(102, 102, 102);" class="">提现时积分与现金的兑换比例，多少积分等于1元</text>
			</view>
			<view class="font-weight_bold margin-top_40rpx">
				提现额度
			</view>
			<view class="edit flex-start-center padding-left_30rpx margin-top_16rpx">
				<input type="number" class="uni-input" v-model="form.withdrawal_commission_condition"
					placeholder="请输入提现额度" />


			</view>
			<view class="margin-top_10rpx">
				<text style="color: rgb(102, 102, 102);" class="">金额达到此额度时才能提现</text>
			</view>
			<view class="font-weight_bold margin-top_40rpx">
				提现手续费
			</view>
			<view class="edit flex-start-center padding-left_30rpx margin-top_16rpx">
				<input maxlength="3" type="number" class="uni-input" v-model="form.withdrawal_fees_ratio"
					placeholder="请输入提现手续费最多不能100" />


			</view>
			<view class="margin-top_10rpx">
				<text style="color: rgb(102, 102, 102);" class="">提现时扣除的提现手续费,空为不扣除提现手续费</text>
			</view>
			<view class="font-weight_bold margin-top_40rpx">
				每日提现次数
			</view>
			<view class="edit flex-start-center padding-left_30rpx margin-top_16rpx">
				<input type="number" class="uni-input" v-model="form.everyday_withdrawal_num"
					placeholder="请输入每天提现的次数" />


			</view>
			<view class="margin-top_10rpx">
				<text style="color: rgb(102, 102, 102);" class="">每日金额可提现次数</text>
			</view>
			<view class="font-weight_bold margin-top_40rpx">
				每日提现金额
			</view>
			<view class="edit flex-start-center padding-left_30rpx margin-top_16rpx">
				<input type="number" class="uni-input" v-model="form.everyday_withdrawal_amount"
					placeholder="请输入每天提现最高额度" />


			</view>
			<view class="margin-top_10rpx">
				<text style="color: rgb(102, 102, 102);" class="">每日最多可提现金额 </text>
			</view>
		</view>

		<view class="flex-between " style="margin: 40rpx 0 15rpx;">
			<view class="reset flex">
				重置
			</view>
			<view class="confirm flex" @click="sumbmit()">
				确定
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		components: {

		},
		data() {
			return {
				tabIndex: 4,
				changeValue: '',
				current: 0,
				current1: 0,
				token: uni.getStorageSync('login').token,
				items: [{
						value: '1',
						name: '显示',

					},
					{
						value: '2',
						name: '隐藏'
					},



				],
				pay: [{
						value: '1',
						name: '支付宝',

					},
					{
						value: '2',
						name: '微信'
					},
					{
						value: '3',
						name: '全部'
					},



				],
				current: 0,
				form: {
					// 1 开启 2关闭
					withdrawal_switch: '1',
					// 1 支付宝 2微信
					withdrawal_mode: '2',
					// 提现积分换换比
					withdrawal_ratio: '',
					// 用户需多少金额才可提现
					withdrawal_commission_condition: '',
					// 提现手续费
					withdrawal_fees_ratio: '',
					// 每日提现次数
					everyday_withdrawal_num: '',
					// 每日提现金额
					everyday_withdrawal_amount: ''
				}
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			async init() {

				const res = await this.$http.post({
					url: this.$api.config,
					data: {


					},
					headers: {
						'Authorization': `Bearer ${this.token}`
					}

				})
				console.log(res)
				if (res.code == 0) {



					// 跳转到登录页面
					this.$at.releaseKey('submit');
					this.$sun.toast(res.msg, 'none')
					this.$sun.assignObject(this.form, {
						...res.data
					})
					this.current = this.form.withdrawal_switch-1
					this.current1 = this.form.withdrawal_mode-1

				} else {
					this.$at.releaseKey('submit');
					this.$sun.toast(res.msg, 'none')
				}
			},

			radioChange: function(evt) {
				for (let i = 0; i < this.items.length; i++) {
					if (this.items[i].value === evt.detail.value) {
						this.current = i;
						this.form.withdrawal_switch = evt.detail.value
						break;
					}
				}
			},
			radioChange1: function(evt) {
				this.current1 = evt.detail.value-1;
				this.form.withdrawal_mode = evt.detail.value
			},
			sumbmit() {
				this.$at.uniDoFunc({
					key: 'submit',
					success: async () => {
						this.$at.lockKey('submit');
						// 登录 需要进行判断当前账号密码 和账号归属店铺及角色是否又选择
						if (!this.form.withdrawal_ratio) {
							this.$sun.toast("请输入兑换比例", 'none')
							this.$at.releaseKey('submit');
						} else if (!this.form.withdrawal_fees_ratio) {
							this.$sun.toast("请输入提现手续费", 'none')
							this.$at.releaseKey('submit');
						} else if (!this.form.everyday_withdrawal_num) {
							this.$sun.toast('请输入每日提现次数', 'none')
							this.$at.releaseKey('submit');
						} else if (!this.form.withdrawal_commission_condition) {
							this.$sun.toast('请输入用户需多少金额才可提现', 'none')
							this.$at.releaseKey('submit');
						} else if (!this.form.everyday_withdrawal_amount) {
							this.$sun.toast('请输入每日提现金额', 'none')
							this.$at.releaseKey('submit');
						} else {


							console.log((this.form))
							this.$at.releaseKey('submit');
							const saveOrUpdate = this.isEdit ? this.$api.editClassify : this.$api
								.upConfig;
							const res = await this.$http.post({
								url: saveOrUpdate,
								data: {

									...this.form
								},
								headers: {
									'Authorization': `Bearer ${this.token}`
								}

							})
							console.log(res)
							if (res.code == 0) {



								// 跳转到登录页面
								this.$at.releaseKey('submit');
								this.$sun.toast(res.msg, 'none')


							} else {
								this.$at.releaseKey('submit');
								this.$sun.toast(res.msg, 'none')
							}
						}

					}
				});
			}
		}
	}
</script>

<style lang="less" scoped>
	.addSpecificationPage {
		padding: 16rpx;

		.reset {
			width: 260rpx;
			height: 88rpx;
			background: rgb(255, 255, 255);
		}

		.confirm {
			width: 428rpx;
			height: 88rpx;
			background-color: rgb(42, 137, 255);
			color: rgb(255, 255, 255);

			font-size: 32rpx;
			font-weight: 400;
		}

		.addSpecificationContent {

			background: rgb(255, 255, 255);
			padding: 30rpx;

			.edit {

				height: 88rpx;
				background: rgb(246, 248, 255);



			}

			.myNmae {

				background-color: #fff;
				min-width: 50rpx;

				.avatar {
					width: 84rpx;
					height: 84rpx;
				}

				input {
					text-align: right;
				}

				.backgroundImg {

					height: 154rpx;


				}

				.uni-textarea {
					margin-top: 20rpx;

					textarea {
						width: 100%;
						box-sizing: border-box;
						border-radius: 10px;


						border-radius: 10px;
						background-color: rgb(246, 251, 255);
						padding: 15rpx 15rpx 15rpx 15rpx;
					}
				}

			}
		}
	}

	page {
		background: #f6f6f6;
	}
</style>